import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JRadioButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JToggleButton;
import javax.swing.JLabel;
import javax.swing.Box;
import javax.swing.UIManager;
import javax.swing.JSeparator;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JCheckBox;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class ProblemSettings extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JPanel buttonPane;
	private Problem problem;
	private boolean MTS = false;

	
	
	/**
	 * Create the dialog.
	 */
	public ProblemSettings(Problem prob) {
		problem = prob;
		MTS = problem.isMTS();
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setBounds(100, 100, 304, 175);
		getContentPane().setLayout(null);
		contentPanel.setBounds(0, 0, 288, 134);
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel);
		
		Box verticalBox = Box.createVerticalBox();
		verticalBox.setBorder(new LineBorder(new Color(130, 135, 144), 1, true));
		
		JLabel lblSampleMode = new JLabel("Sample Mode:");
		{
			buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			{
				JButton okButton = new JButton("OK");
				okButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						problem.setMTS(MTS);
						ProblemSettings.this.dispose();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						ProblemSettings.this.dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGap(10)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(verticalBox, GroupLayout.PREFERRED_SIZE, 190, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblSampleMode)))
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addContainerGap()
							.addComponent(buttonPane, GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)))
					.addContainerGap())
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblSampleMode)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(verticalBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(buttonPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(129, Short.MAX_VALUE))
		);
		
		final JRadioButton rdbtnNewRadioButton = new JRadioButton("Match to Sample");
		final JRadioButton rdbtnDelayedMatchTo = new JRadioButton("Delayed Match to Sample");
		
		if (MTS){
			rdbtnNewRadioButton.setSelected(true);
			rdbtnDelayedMatchTo.setSelected(false);
		} else {
			rdbtnDelayedMatchTo.setSelected(true);
			rdbtnNewRadioButton.setSelected(false);
		}
		
		rdbtnDelayedMatchTo.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent arg0) {
				rdbtnNewRadioButton.setSelected(false);
				rdbtnDelayedMatchTo.setSelected(!(rdbtnNewRadioButton.isSelected()));
				MTS = false;
			}
		});
		rdbtnNewRadioButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent arg0) {
				rdbtnNewRadioButton.setSelected(true);
				rdbtnDelayedMatchTo.setSelected(!(rdbtnNewRadioButton.isSelected()));
				MTS = true;
			}
		});
		verticalBox.add(rdbtnNewRadioButton);
		
		
		verticalBox.add(rdbtnDelayedMatchTo);
		contentPanel.setLayout(gl_contentPanel);
		
		this.setVisible(true);
	}
}
